﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BUS;
using DTO;

namespace FastDeal.Control
{
    public partial class wuc_BinhLuanMoiNhat : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadDanhSachBinhLuanMoiNhat();
        }

        /// <summary>
        /// Load danh sach bình luận mới nhất
        /// </summary>
        private void LoadDanhSachBinhLuanMoiNhat()
        {
            NhanXet_BUS db = new NhanXet_BUS();
            List<NhanXet> list = new List<NhanXet>();
            list = db.LayDanhSach_NhanXet();
            int sl = list.Count;
            if (sl != 0)
            {
                //Lấy thông tin của user:
                TaiKhoan_BUS db1 = new TaiKhoan_BUS();
                TaiKhoan tk1 = new TaiKhoan();
                tk1 = db1.LayThongTin_TaiKhoan(list[sl-1].UserID);
                link1.Text =tk1.UserName.ToUpper() + ": " + list[sl - 1].NoiDung.Substring(0, 30).ToString() + "...";
                link1.NavigateUrl = "~/ChiTietKhuyenMai.aspx?ID=" + list[sl - 1].MaKhuyenMai.ToString();

                tk1 = db1.LayThongTin_TaiKhoan(list[sl - 2].UserID);
                link2.Text = tk1.UserName.ToUpper() + ": " + list[sl - 2].NoiDung.Substring(0, 30).ToString() + "...";
                link2.NavigateUrl = "~/ChiTietKhuyenMai.aspx?ID=" + list[sl - 2].MaKhuyenMai.ToString();

                tk1 = db1.LayThongTin_TaiKhoan(list[sl - 1].UserID);
                link3.Text = tk1.UserName.ToUpper() + ": " + list[sl - 3].NoiDung.Substring(0, 30).ToString() + "...";
                link3.NavigateUrl = "~/ChiTietKhuyenMai.aspx?ID=" + list[sl - 3].MaKhuyenMai.ToString();

                tk1 = db1.LayThongTin_TaiKhoan(list[sl - 1].UserID);
                link4.Text = tk1.UserName.ToUpper() + ": " + list[sl - 4].NoiDung.Substring(0, 30).ToString() + "...";
                link4.NavigateUrl = "~/ChiTietKhuyenMai.aspx?ID=" + list[sl - 4].MaKhuyenMai.ToString();

                tk1 = db1.LayThongTin_TaiKhoan(list[sl - 1].UserID);
                link5.Text = tk1.UserName.ToUpper() + ": " + list[sl - 5].NoiDung.Substring(0, 30).ToString() + "...";
                link5.NavigateUrl = "~/ChiTietKhuyenMai.aspx?ID=" + list[sl - 5].MaKhuyenMai.ToString();
            }
            else
            {
                link1.Visible = false;
                link2.Visible = false;
                link3.Visible = false;
                link4.Visible = false;
                link5.Visible = false;
            }
        }
    }
}